#/bin/sh

WORK_DIR=$(pwd)
[[ $EUID -ne 0 ]] && echo 'Error: This script must be run as root!' && exit 1


function init_config_aliyun_repository() {
    ping mirrors.aliyun.com
    # 1. 下载CentOS 7的repo文件
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
    curl -o /etc/yum.repos.d/CentOS-Base-ali.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    # 下载 CentOS 8的repo文件
    curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
    # 2. 更新yum 源
    yum clean all
    yum makecache
    # 3. 备份配置文件
    sed -i 's/http:/https:/g' /etc/yum.repos.d/CentOS-Base-ali.repo
    # 4. 更新生效
    # 清除yum缓存
    yum clean all
    # 缓存阿里云源，比较耗费时间，空闲时间时执行
    yum makecache
    # 测试阿里云源
    yum list


}

function init() {
/bin/cat<<EOF >> /etc/bashrc

export PS1="[\u@\h \W]<\D{%Y%m%d %H:%M:%S}>\$"
EOF
source /etc/bashrc
}

function base_tools() {
   yum -y install lrzsz git wget -y
   # 快速查找文件的命令
   yum -y install mlocate -y
   yum install -y vim lrzsz gcc gcc-c++ openssl-devel gddevel pam-devel pam expat-devel pcre-devel GeoIP-devel bison \
   ncurses ncurses-devel nfs-utils make unzip zip openssl openssl-devel cmake libaio openssh-clients perlTime-HiRes mtr openssh-clients net-tools iptables-services tree initscripts ntpdate wget nc tcpdump
   # others
   yum install tree -y
   yum install python3 -y
}



# 关闭Selinux
function close_selinux() {
    /bin/sed -i 's/SELINUX=permissive/SELINUX=disabled/' /etc/selinux/config
    /bin/sed -i 's/SELINUX=enforcing/SELINUX=disabled/'  /etc/selinux/config
}

# 关闭一些不常用的服务
function close_uncommon_used_service() {
# 邮件传输代理
systemctl stop 'postfix'
systemctl disable 'postfix'
# 传统网络管理服务，已被network 代替
systemctl stop 'NetworkManager'
systemctl disable 'NetworkManager'
# 自动错误报告工具
systemctl disable 'abrt-ccpp'
}



# CPU的能源管理模块优化，这里调整的是 pstate 和 cstate 数值。
function  change_intel_Pstate() {

sed -i '/GRUB_CMDLINE_LINUX/{s/"$//g;s/$/ intel_pstate=disable intel_idle.max_cstate=0 processor.max_cstate=1 idle=poll"/}' /etc/default/grub

}

# alias 别名
function alias_changes() {
cat > /etc/profile.d/Je.sh <<EOF

alias ls='ls -hAF --color=auto --time-style=long-iso'

alias ll='ls -l'

alias cp='cp -i'

alias mv='mv -i'

alias rm='rm -i'

alias ds='ds -h'

alias df='df -h'

alias grep='egrep --color'


EOF

}

# 设置操作系统最大的文件打开数
function open_files_max_set() {
# /etc/security/limits.conf 文件用于设置用户或组的资源限制。这些限制包括进程数、打开文件数、内存使用
found=`grep -c "^* soft nproc" /etc/security/limits.conf`

if ! [ $found -gt "0" ];then
cat >> /etc/security/limits.conf << EOF

* soft nproc 2048

* hard nproc 16384

* soft nofile 8192

* hard nofile 65536

EOF
fi

}

function main() {

}

main